package com.ptswitch.material.pages.contract;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ptswitch.material.model.contract.ContractAttachment;
import com.ptswitch.material.pages.base.MaterialBasePage;
import com.ptswitch.material.service.ContractAttachmentService;
import com.ptswitch.material.util.HlogConstants;

public class DeleteAttachment extends MaterialBasePage {
    @Inject
    private ContractAttachmentService uploadSer;
    @InjectPage
    private ViewContract viewContract;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object delete(String id) {
        ContractAttachment upload = uploadSer.findById(id);
//		mustBuyer();
        checkUserIsEqual(upload.getUsername());
        getWebUtil().delete(upload);
        uploadSer.delete(upload);
        hlog(HlogConstants.deleteUpload, upload);
        return viewContract.initialize(upload.getOwnerId());
    }
}
